NexusPi Git Node
Commit a62e85a6b018ca84a664772928dd362eecda6a4d
Parents : 4b9dc7b
Author : Chad Attermann <attermann@gmail.com>
Date : 2026-03-01T12:54:43-07:00
Added base-level exception handling.
Changes
4 files changed, 56 insertions(+), 13 deletions(-)
Diff
diff --git a/FileSystem.cpp b/FileSystem.cpp
index 1ae4bce..d2f68f6 100644
--- a/FileSystem.cpp
+++ b/FileSystem.cpp
@@ -124,7 +124,7 @@ bool FileSystem::format() {
return true;
}
catch (std::exception& e) {
- ERROR("FileSystem reformat Exception: " + std::string(e.what()));
+ ERRORF("FileSystem reformat Exception: %s", e.what());
}
return false;
}
@@ -154,7 +154,7 @@ bool FileSystem::reformat() {
return true;
}
catch (std::exception& e) {
- ERROR("FileSystem reformat Exception: " + std::string(e.what()));
+ ERRORF("FileSystem reformat Exception: %s", e.what());
}
return false;
}
@@ -417,7 +417,7 @@ void FileSystem::dumpDir(const char* dir) {
/*virtua*/ bool FileSystem::create_directory(const char* directory_path) {
TRACEF("create_directory: creating directory %s", directory_path);
if (!FS.mkdir(directory_path)) {
- ERROR("create_directory: failed to create directory " + std::string(directory_path));
+ ERRORF("create_directory: failed to create directory %s", directory_path);
return false;
}
return true;
@@ -430,7 +430,7 @@ void FileSystem::dumpDir(const char* dir) {
#else
if (!FS.rmdir(directory_path)) {
#endif
- ERROR("remove_directory: failed to remove directory " + std::string(directory_path));
+ ERRORF("remove_directory: failed to remove directory %s", directory_path);
return false;
}
return true;
@@ -441,7 +441,7 @@ void FileSystem::dumpDir(const char* dir) {
std::list<std::string> files;
File root = FS.open(directory_path);
if (!root) {
- ERROR("list_directory: failed to open directory " + std::string(directory_path));
+ ERRORF("list_directory: failed to open directory %s", directory_path);
return files;
}
File file = root.openNextFile();
diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino
index c9e2883..33102b8 100644
--- a/RNode_Firmware.ino
+++ b/RNode_Firmware.ino
@@ -113,7 +113,15 @@ protected:
virtual void handle_incoming(const RNS::Bytes& data) {
TRACEF("LoRaInterface.handle_incoming: (%u bytes) data: %s", data.size(), data.toHex().c_str());
TRACE("LoRaInterface.handle_incoming: sending packet to rns...");
- InterfaceImpl::handle_incoming(data);
+ try {
+ InterfaceImpl::handle_incoming(data);
+ }
+ catch (const std::bad_alloc&) {
+ ERROR("LoRaInterface::handle_incoming: bad_alloc - out of memory");
+ }
+ catch (std::exception& e) {
+ ERRORF("LoRaInterface::handle_incoming: %s", e.what());
+ }
}
virtual void send_outgoing(const RNS::Bytes& data) {
// CBA NOTE header will be addded later by transmit function
@@ -148,23 +156,32 @@ protected:
}
// Perform post-send housekeeping
- InterfaceImpl::handle_outgoing(data);
+ try {
+ InterfaceImpl::handle_outgoing(data);
+ }
+ catch (const std::bad_alloc&) {
+ ERROR("LoRaInterface::handle_outgoing: bad_alloc - out of memory");
+ }
+ catch (std::exception& e) {
+ ERRORF("LoRaInterface::handle_outgoing: %s", e.what());
+ }
}
};
// CBA logger callback
void on_log(const char* msg, RNS::LogLevel level) {
-/*
+ // Using individual Serial.print statements to avoid memory allocation for String
Serial.print(RNS::getTimeString());
Serial.print(" [");
Serial.print(RNS::getLevelName(level));
Serial.print("] ");
Serial.println(msg);
Serial.flush();
-*/
+/*
String line = RNS::getTimeString() + String(" [") + RNS::getLevelName(level) + "] " + msg + "\n";
Serial.print(line);
Serial.flush();
+*/
#ifdef HAS_SDCARD
File file = SD.open("/logfile.txt", FILE_APPEND);
@@ -561,7 +578,7 @@ void setup() {
TRACE("FILE: destination_table");
RNS::Bytes content;
if (filesystem.read_file("/destination_table", content) > 0) {
- TRACE(content.toString() + "\r\n");
+ TRACE(content.toString().c_str());
}
#endif // NDEBUG
@@ -570,6 +587,7 @@ void setup() {
// Set sane memory limits based on hardware-specific availability
RNS::Transport::path_table_maxsize(50);
+ RNS::Transport::announce_table_maxsize(50);
RNS::Transport::hashlist_maxsize(50);
RNS::Transport::max_pr_tags(32);
RNS::Identity::known_destinations_maxsize(50);
@@ -580,8 +598,11 @@ void setup() {
RNS::Transport::set_transmit_packet_callback(on_transmit_packet);
Serial.write("Starting RNS...\r\n");
+#if defined(RNS_MEM_LOG)
+ RNS::loglevel(RNS::LOG_MEM);
+#else
RNS::loglevel(RNS::LOG_TRACE);
- //RNS::loglevel(RNS::LOG_MEM);
+#endif
HEAD("Registering LoRA Interface...", RNS::LOG_TRACE);
lora_interface = new LoRaInterface();
@@ -635,8 +656,11 @@ void setup() {
//reticulum.clear_caches();
}
}
+ catch (const std::bad_alloc&) {
+ ERROR("RNS startup failed: bad_alloc - out of memory");
+ }
catch (std::exception& e) {
- ERROR("RNS startup failed: " + std::string(e.what()));
+ ERRORF("RNS startup failed: %s", e.what());
}
#endif // HAS_RNS
}
@@ -2017,7 +2041,15 @@ void loop() {
#ifdef HAS_RNS
// CBA
if (reticulum) {
- reticulum.loop();
+ try {
+ reticulum.loop();
+ }
+ catch (const std::bad_alloc&) {
+ ERROR("RNS loop failed: bad_alloc - out of memory");
+ }
+ catch (std::exception& e) {
+ ERRORF("RNS loop failed: %s", e.what());
+ }
}
#endif
diff --git a/extra_script.py b/extra_script.py
index 2469070..2f02219 100644
--- a/extra_script.py
+++ b/extra_script.py
@@ -58,6 +58,7 @@ def pre_clean(env):
env.Execute("rm -f " + project_dir + "/Release/" + env.subst("$PROGNAME") + ".zip")
env.Execute("rm -f " + project_dir + "/Debug/" + env.subst("$PROGNAME") + ".elf")
env.Execute("rm -f " + project_dir + "/Debug/" + env.subst("$PROGNAME") + ".map")
+ env.Execute("rm -f " + project_dir + "/Release/" + env.subst("$PROGNAME") + "_debug.zip")
def full_clean(env):
print("--- Executing full_clean steps...")
@@ -161,6 +162,11 @@ def firmware_package(env):
env.Execute(zip_cmd)
env.Execute("cp " + build_dir + "/" + env.subst("$PROGNAME") + ".elf " + project_dir + "/Debug/.")
env.Execute("cp " + build_dir + "/" + env.subst("$PROGNAME") + ".map " + project_dir + "/Debug/.")
+ zip_cmd = "zip --junk-paths "
+ zip_cmd += project_dir + "/Release/rnode_firmware_" + variant + "_debug.zip "
+ zip_cmd += build_dir + "/" + env.subst("$PROGNAME") + ".elf "
+ zip_cmd += build_dir + "/" + env.subst("$PROGNAME") + ".map "
+ env.Execute(zip_cmd)
elif (platform == "nordicnrf52"):
env.Execute("cp " + build_dir + "/" + env.subst("$PROGNAME") + ".zip " + project_dir + "/Release/.")
env.Execute("python " + project_dir + "/release_hashes.py > " + project_dir + "/Release/release.json")
diff --git a/platformio.ini b/platformio.ini
index 715a7e4..1bcb08b 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -455,11 +455,16 @@ build_flags =
${env.build_flags}
-DBOARD_MODEL=BOARD_HELTEC32_V4
-DARDUINO_USB_CDC_ON_BOOT=1
+ ; CBA TEST
+ ;-DRNS_USE_TLSF=1
+ ;-DRNS_USE_ALLOCATOR=1
+ ;-DRNS_MEM_LOG
lib_deps =
${env.lib_deps}
XPowersLib@^0.2.1
microReticulum=symlink://../microReticulum
monitor_filters = esp32_exception_decoder
+upload_speed = 921600
[env:wiscore_rak4631-local]
platform = nordicnrf52
Served by rngit 1.5.4 - Generated in 0.02s